<%@ page import="com.lyc.cart.bean.CartItem" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/12/12
  Time: 11:56
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>我的购物车</title>
</head>
<body>
<div>欢迎${sessionScope.userAccount.nickName} 进入我的购物车；ID：${sessionScope.userAccount.id}
<%  List<CartItem> cartItems =(List<CartItem> ) request.getAttribute("cartItems");

    for (CartItem cartItem : cartItems) {
        if (cartItem == null){%>
              <h2>购物车空空如也，快去逛逛吧。。。。。。。</h2>
     <% }%>
            <div id="cart" style="width: 750px;height: 150px;border: 1px solid rosybrown">
                <input type="checkbox" width="20px" name="payCheck">
                <% float totalMoney=(float) (cartItem.getBuyNumbers()*cartItem.getPrice()*cartItem.getDiscount());%>
                <br>
                        <img width="100px" height="100px" src="<%=request.getContextPath()%>/<%=cartItem.getProductImgurl()%>" alt="图片无法加载">
                    <div >
                        <span>商品编号：<%=cartItem.getProductId()%>；</span>
                        <span>书名：<%=cartItem.getProductName()%>；</span>
                        <span>价格：<%=cartItem.getPrice()%>元/本；</span>
                        <span id="buyNumbers">购买数量:<%=cartItem.getBuyNumbers()%>本；</span>
                       <span>总计：<%=totalMoney%>元；</span>
                        <a href="${pageContext.request.contextPath}/bookInfo?methodName=myOrder&uid=${sessionScope.userAccount.id}&productId=<%=cartItem.getProductId()%>">立即付款</a>
                        <button type="button" name="deleteProduct">  删除商品</button>
                    </div>
            </div>
 <script type="text/javascript">
        window.onload=function () {
            var deleteProduct=document.getElementsByName("deleteProduct");
            for (var i=0;i<deleteProduct.length;i++){
                deleteProduct[i].onclick=function () {
                    var request=new XMLHttpRequest();
                    var url="${pageContext.request.contextPath}/bookInfo";
                    request.open("POST",url);
                    //用post提交要设置请求头
                    request.setRequestHeader( "Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
                    var param="methodName=deleteBookToCart&productId=<%=cartItem.getProductId()%>";
                    request.send(param);
                    request.onreadystatechange=function () {
                        if (request.readyState==4){
                            if (request.status==200 || request.status==304) {
                                alert(request.response);
                            }
                        }
                    }
                }
            }

        }
    </script>
  <%  }
%>

<%--<c:choose>--%>
    <%--<c:when test="${empty requestScope.cartItems}">--%>
        <%--购物车空空如也。。。。。--%>
    <%--</c:when>--%>
    <%--<c:otherwise>--%>
        <%--<c:forEach items="${requestScope.cartItems}" var="cartItems">--%>
                <%--<div style="width: 400px;height: 300px ;overflow: hidden">--%>
                    <%--<div style="float: left"><img width="200px" height="300px" src="${pageContext.request.contextPath}/${cartItems.productImgurl}" alt="图片无法加载"></div>--%>
                <%--</div>--%>
                <%--<div style="float: left">--%>
                    <%--书名：${cartItems.productName}--%>
                    <%--价格：${cartItems.price}--%>
                    <%--购买数量:${cartItems.buyNumbers}本--%>
                    <%--总计：${(cartItems.buyNumbers)*(cartItems.price)*(discount)}元--%>
                    <%--<button> 立即付款</button>--%>
                    <%--<button>  删除商品</button>--%>
                <%--</div>--%>
        <%--</c:forEach>--%>
    <%--</c:otherwise>--%>
<%--</c:choose>--%>
</body>
</html>
